
import pandas as pd
from sklearn.model_selection import train_test_split
import abc

class Readdata(object):

    __metaclass__ = abc.ABCMeta

    def __init__(self):
        self.fname = 'train.csv'

    def read_dataet(self,fname):
        data = pd.read_csv(fname, index_col=0)
        data.drop(['Name', 'Ticket', 'Cabin'], axis=1, inplace=True)
        lables = data['Sex'].unique().tolist()
        data['Sex'] = [*map(lambda x: lables.index(x) , data['Sex'])]
        lables = data['Embarked'].unique().tolist()
        data['Embarked'] = data['Embarked'].apply(lambda n: lables.index(n))
        data = data.fillna(0)

        return data

    def processData(self):
        train = self.read_dataet(self.fname)
        y = train['Survived'].values
        X = train.drop(['Survived'], axis=1).values
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
        self.trainAndtest(X_train,y_train,X_test,y_test)

    @abc.abstractmethod
    def trainAndtest(self,X_train,y_train,X_test,y_test):
        pass












